package com.caesar.Date.first_generation;

import org.junit.jupiter.api.Test;

import java.util.Date;

/**
 * @author caesar
 * @date 2025/7/15
 * @Description:java.util.Date
 *          Date类中大部分方法都已过时。它的对象可以表示一个日期时间的瞬时。
 * @apiNote
 */
public class TestDate {
    @Test
    public void test(){
        Date now = new Date();
        System.out.println("now = " + now);
        //now = Tue Jul 15 09:00:56 CST 2025
    }

    @Test
    public void test2(){
        Date now = new Date();
        long time = now.getTime();
        //距离1970-1-1 8:0:0 的毫秒值
        System.out.println("time = " + time);
        //time = 1752541333556
    }

    @Test
    public void test3(){
        long time = System.currentTimeMillis();//更简洁
        //距离1970-1-1 8:0:0 的毫秒值
        System.out.println("time = " + time);
        //time = 1752541333556
    }

    @Test
    public void test4(){
        long start = System.currentTimeMillis();
        String str = "";
        for(int i=1; i<=100000; i++){
            str += i;
        }
        long end = System.currentTimeMillis();
        System.out.println("耗时：" + (end-start));//耗时：2853
    }

    @Test
    public void test5(){
        long time = 8645615122L;
        Date d = new Date(time);
        System.out.println("d = " + d);
        //d = Sat Apr 11 09:33:35 CST 1970
    }
}
